import requests
import ddddocr

# 登录的url地址
url = "https://www.tianapi.com/system/actuser.php?action=login"

"""
获取验证码

安装 ddddocr
pip install ddddocr
"""

session = requests.session()
code_url = "https://www.tianapi.com/system/actuser.php?action=autocode"

content = session.get(code_url).content
with open("code.png", "wb") as fp:
    fp.write(content)

ocr = ddddocr.DdddOcr(show_ad=False)

image = open("code.png", "rb").read()
verify_code = ocr.classification(image)  # 验证码

# 构建参数
params = {
    "loginid": "friendship_liu",
    "password": "asdf1234",
    "autocode": verify_code
}

text = session.post(url, data=params).text
#

console_url = "https://www.tianapi.com/console/"
console_text = session.get(console_url).text
print(console_text)